using B.S.BasicData.Infrature;
using Microsoft.EntityFrameworkCore;
using MediatR;
using System.Reflection;
using B.S.BasicData.Api;
using B.S.BasicData.Api.Services;
namespace B.S.BasicData.Api
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddControllers();
            // 注册AppDbContext，使用SqlServer，连接字符串从配置读取
            builder.Services.AddDbContext<AppDbContext>(options =>
                options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
            // 注册仓储
            builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();

            //中介者
            builder.Services.AddMediatR(x=>x.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));


            builder.Services.AddSwaggerGen();

            // 七牛云配置（请填写你自己的信息）
            var qiniuConfig = new QiniuConfig
            {
                AccessKey = "SHizDpfwT7i12RgH104udcS642OSaoU2NerH3uSY",
                SecretKey = "htETOZTrOKBDiIW-KnpqSnx6hyP7jbC8vbznNPXr",
                Bucket = "ln666",
                Domain = "http://t054m6qx4.hb-bkt.clouddn.com/",
                Zone = "z1" // 华东
            };
            builder.Services.AddSingleton(qiniuConfig);
            builder.Services.AddScoped<QiniuUploadService>();



            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseAuthorization();
            //跨域请求
            app.UseCors(u=>u.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

            app.MapControllers();
            app.UseStaticFiles();
            app.Run();
        }
    }
}
